/**
* 版权所有:版权所有(C) 2020，卓信科技
* 系统名称:FOL-客户管理系统
* 文件名称:GlobalFileUtil.java
* 模块名称:文件工具类
* 创建日期:2020年5月19日
* 作        者:Baisong
* 内容摘要:文件工具类
*/
package com.zx.sframe.util.file;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zx.emanage.util.gen.DateUtil;
import com.zx.emanage.util.gen.GlobalVal;
import com.zx.emanage.util.gen.SysUtil;
import com.zx.emanage.util.gen.ZipFile;
import com.zx.emanage.util.gen.entity.BatchCompressImgVO;
import com.zx.platform.syscontext.PlatformGlobalVar;

/**
 * 类 名 称:GlobalFileUtil
 *
 * 内容摘要:文件工具类
 *
 * 作 者:Baisong
 */
public class GlobalFileUtil 
{
	private final static Integer TIMEOUT = 10*1000;
	/**
	 * 获取文件扩展名
	 * 
	 * @param filename
	 *            文件名
	 * @return
	 */
	public static String getExtensionName(String filename) 
	{
		//判断
		if ((filename != null) && (filename.length() > 0)) 
		{
			int dot = filename.lastIndexOf('.');
			//判断
			if ((dot > -1) && (dot < (filename.length() - 1))) 
			{
				return filename.toLowerCase().substring(dot + 1);
			}
		}
		return filename;
	}

	/**
	 * @author Allen
	 * @param 1、上传的文件流，2、当前用户的ID，3、上传文件名
	 * @return 返回保存的文件路径
	 * */
	public static String saveUploadFile(InputStream fileStream, String userId,
			String srcFileName) throws IOException 
	{
		
		String catalog = DateUtil.date2String(new Date(), "yyyyMM");
		String postfix = "";
		//判断
		if (srcFileName.lastIndexOf(".") > -1)
		{
		    postfix = srcFileName.substring(srcFileName.lastIndexOf(".")).toLowerCase(); 
		}
        String fileName = UUID.randomUUID().toString();
        // String fileName = ""+System.currentTimeMillis();
		/*String fileName = srcFileName;
		if(srcFileName.lastIndexOf(System.getProperty("file.separator")) > -1){
			fileName =  fileName.substring(fileName.lastIndexOf(System.getProperty("file.separator"))+1);
		}
		String postfix = "";
		if (fileName.lastIndexOf(".") > -1) {
			postfix = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); 
			fileName =  fileName.substring(0,fileName.lastIndexOf("."));
		}
		
		String now = ""+System.currentTimeMillis();
		fileName = fileName+ "_" + now.substring(now.length()-6);
		
		fileName = fileName.replaceAll(">", "＞").replaceAll("<", "＜").replaceAll("%", "％").replaceAll("&", "＆").replaceAll(";", "；");
		 */ // String fileName = ""+System.currentTimeMillis();
		/*String fileName = srcFileName;
		if(srcFileName.lastIndexOf(System.getProperty("file.separator")) > -1){
			fileName =  fileName.substring(fileName.lastIndexOf(System.getProperty("file.separator"))+1);
		}
		String postfix = "";
		if (fileName.lastIndexOf(".") > -1) {
			postfix = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); 
			fileName =  fileName.substring(0,fileName.lastIndexOf("."));
		}
		
		String now = ""+System.currentTimeMillis();
		fileName = fileName+ "_" + now.substring(now.length()-6);
		
		fileName = fileName.replaceAll(">", "＞").replaceAll("<", "＜").replaceAll("%", "％").replaceAll("&", "＆").replaceAll(";", "；");
		 */ // String fileName = ""+System.currentTimeMillis();
		/*String fileName = srcFileName;
		if(srcFileName.lastIndexOf(System.getProperty("file.separator")) > -1){
			fileName =  fileName.substring(fileName.lastIndexOf(System.getProperty("file.separator"))+1);
		}
		String postfix = "";
		if (fileName.lastIndexOf(".") > -1) {
			postfix = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); 
			fileName =  fileName.substring(0,fileName.lastIndexOf("."));
		}
		
		String now = ""+System.currentTimeMillis();
		fileName = fileName+ "_" + now.substring(now.length()-6);
		
		fileName = fileName.replaceAll(">", "＞").replaceAll("<", "＜").replaceAll("%", "％").replaceAll("&", "＆").replaceAll(";", "；");
		 */
		// String isDebug = GlobalVal.getProperty("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");

		String realPath = "";
		//判断
		if ("1".equals(isDebug))
		{
			String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
			nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
			realPath = nowPath + "/resources/upload/" + catalog;
		}
		else
		{

			// realPath = GlobalVal.getProperty("realUploadCatalog") + "/" + catalog;
			realPath = GlobalVal.getProperty("realUploadCatalog") + "/" + catalog;
		}

		File dir = new File(realPath);
		//判断
		if (!dir.exists())
		{
			dir.mkdirs();
		}
		FileOutputStream fout = new FileOutputStream(new File(realPath + "/" + fileName + postfix));
		
		BufferedInputStream bis = new BufferedInputStream(fileStream);
		byte[] cacheArray = new byte[2048];
		int size;
		//循环
		while ((size = bis.read(cacheArray)) != -1)
		{
			fout.write(cacheArray, 0, size);
		}

		fout.close();   
		bis.close();    
		return "/" + catalog + "/" + fileName + postfix;
	}
	
	/**
     * @author Allen
     * @param 1、上传的文件流，2、当前用户的ID，3、上传文件名
     * @return 返回保存的文件路径
     * */
    public static String saveUploadFileForMoa(InputStream fileStream, String userId,
            String srcFileName, String catalog) throws IOException 
    {
        
		// String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");
        String realPath = "";
      //判断
        if ("1".equals(isDebug)) 
        {
            String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
            nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
            realPath = nowPath + "/resources/upload/" + catalog;
        }
        else
        {

			// realPath = PlatformGlobalVar.SYS_PROPERTIES.get("realUploadCatalog") + "/" +
			// catalog;
			realPath = GlobalVal.getProperty("isDebugUpload") + "/" + catalog;
        }

        File dir = new File(realPath);
      //判断
        if (!dir.exists())
        {
            dir.mkdirs();
        }
        FileOutputStream fout = new FileOutputStream(new File(realPath + "/" + srcFileName));
        
        BufferedInputStream bis = new BufferedInputStream(fileStream);
        byte[] cacheArray = new byte[2048];
        int size;
        //循环
        while ((size = bis.read(cacheArray)) != -1)
        {
            fout.write(cacheArray, 0, size);
        }

        fout.close();   
        bis.close();
        // 生成缩略图2018-3-28
		// String isCompressImg = PlatformGlobalVar.SYS_PROPERTIES.get("isCompressImg");
		String isCompressImg = GlobalVal.getProperty("isCompressImg");
		// 判断
        if ("true".equals(isCompressImg))
        {
            SysUtil.asyncCompress("/" + catalog + "/" + srcFileName);
        }
        return realPath;
    }
	/**
	 * //图片原图路径
	 * 方法名称: getUploadPath
	 * 内容摘要: TODO(这里详细描述这个方法的作用)
	 * @return 
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 下午2:07:21
	 */
	public static String getUploadPath()
	{
		// String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");
		String realPath = "";
		//判断
		if ("1".equals(isDebug))
		{
			String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
			nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
			realPath = nowPath + "/resources/upload";
		}
		else
		{
			// realPath = PlatformGlobalVar.SYS_PROPERTIES.get("realUploadCatalog");
			realPath = GlobalVal.getProperty("realUploadCatalog");
		}
		
		return realPath;
	}
	/**
	 * //图片缩略图路径 2016-10-27
	 * 方法名称: getCompressPath
	 * 内容摘要: TODO(这里详细描述这个方法的作用)
	 * @return 
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 下午2:07:17
	 */
	public static String getCompressPath()
	{
		// String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");
		String realPath = "";
		//判断
		if ("1".equals(isDebug)) 
		{
			String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
			nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
			realPath = nowPath + "/resources/compress";
		}
		else
		{
			// realPath = PlatformGlobalVar.SYS_PROPERTIES.get("realCompressCatalog");
			realPath = GlobalVal.getProperty("realCompressCatalog");
		}
		return realPath;
	}
	/**
	 * 删除文件
	 * @return
	 */
	public static String deleteFile(String file_path)
	{
			String path=getUploadPath()+file_path;
			File file = new File(path);
			//判断
			if (file.exists())
			{
				 file.delete(); 
			}
			return "success";
	}
	/**
	 * 获取图片压缩文件
	 * @param url
	 * @param res
	 * @author baisong
	 * @throws IOException 
	 */
	public static void loadImg(String url,HttpServletResponse res)
	{
		try 
		{
			String imgUrl=getUploadPath()+url;
			// ImgCompress imgCompress=new ImgCompress(imgUrl,"");
			// BufferedImage img=imgCompress.getResizeImg(200, 200);
			try 
			{
				String AllType=getFileContentType(imgUrl);
				String type = url.substring(url.lastIndexOf(".")+1);
				ByteArrayOutputStream out =new ByteArrayOutputStream();
				// ImageIO.write(img,type,out);
				res.setContentType(AllType+";charset=utf-8");
				//判断
				if(!isImg(imgUrl))
				{
					res.setHeader("Content-Disposition", "attachment;filename="+ 
							new String((getFileName(imgUrl)).getBytes(), "iso-8859-1"));
				}
				res.getOutputStream().write(out.toByteArray());
			} 
			finally 
			{
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 方法名称: getFileContentType
	 * 内容摘要: TODO(这里详细描述这个方法的作用)
	 * @param url
	 * @return 
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 上午11:45:00
	 */
	public static String getFileContentType(String url)
	{
		String type = "";
		//判断
		if(url.indexOf(".")>=0)
		{
			type = url.substring(url.lastIndexOf(".")+1);
		}
		//判断
		if(isImg(url))
		{
			return "image/"+type;
		}
		else if("xls,xlsx".indexOf(type)>=0)
		{
			return "application/vnd.ms-excel";
		}
		else if("doc,docx".indexOf(type)>=0)
		{
			return "application/msword";
		}
		else if("txt".indexOf(type)>=0)
		{
			return "text/plain";
		}
		else
		{
			return "application/octet-stream";
		}
	}

	/**
	 * 
	 * 方法名称: isImg 内容摘要: TODO(这里详细描述这个方法的作用)
	 * 
	 * @param url
	 * @return
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 上午11:45:29
	 */
	public static boolean isImg(String url)
	{
		String type = "";
		// 判断
		if (url.indexOf(".") >= 0)
		{
			type = url.substring(url.lastIndexOf(".")+1);
		}
		return "jpg,png,jpeg,gif,bmp,wbmp".indexOf(type)>=0;
	}

	/**
	 * 
	 * 方法名称: getFileName 内容摘要: TODO(这里详细描述这个方法的作用)
	 * 
	 * @param url
	 * @return
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 上午11:45:39
	 */
	public static String getFileName(String url) 
	{
		// 判断
		if (url.indexOf("/") >= 0) 
		{
			url = url.substring(url.lastIndexOf("/")+1);
		}
		return url;
	}
	/**
	 * 生成图片压缩文件并保存到指定路径
	 * @param url
	 * @param res
	 * @author baisong
	 * @throws IOException 
	 */
	public static void saveImgCompress(String url)
	{
		try 
		{
			// 判断
			if (!isImg(url)) 
			{
				return;
			}
			//文件类型
			String type= url.substring(url.lastIndexOf(".")+1);
			//获取可操作的图片格式
			// String isDebug [] =
			// PlatformGlobalVar.SYS_PROPERTIES.get("imgType").split(",");
			String isDebug[] = GlobalVal.getProperty("imgType").split(",");

            boolean is_allow = false;
			// 循环
            for (String filetype : isDebug)
            {
				// 判断
                if (filetype != null && type != null && filetype.toLowerCase().equals(type.toLowerCase()))
                {
                    is_allow = true;
                }
            }
            // 判断是否符合
            if (!is_allow)
            {
                return;
            }
			String imgUrl=getUploadPath()+url;
			String saveURL=changeImgName(url);
			// ImgCompress imgCompress=new ImgCompress(imgUrl,saveURL);
			// imgCompress.resize(400, 300);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * 方法名称: changeImgName
	 * 内容摘要: TODO(这里详细描述这个方法的作用)
	 * @param url
	 * @return 
	 *
	 * @author: Baisong
	 * @time:2020年8月25日 上午11:46:22
	 */
	public static String changeImgName(String url)
	{
		String newUrl = "";
		String type = "";
		String compressPath =getCompressPath();
		//判断
		if(url.indexOf(".")>=0)
		{
			newUrl=url.substring(0,url.lastIndexOf("."));
			type = url.substring(url.lastIndexOf(".")+1);
		}
		//判断缩略图保存的目标文件夹 如果没有则创建
		String generateUrl="";
		int num =url.substring(1,url.length()).indexOf("/");
		//判断
		if(num>0)
		{
			generateUrl=url.substring(0,num+1);
		}
		File file=new File(compressPath+generateUrl);
		//判断
		if (!file.exists()) 
		{
			file.mkdirs();
		}
		//返回目标文件路径和文件名称
        return compressPath + newUrl + "." + type;
	}
	/**
	 * 获取图片压缩文件
	 * @param url
	 * @param res
	 * @author baisong
	 * @throws IOException 
	 */
	public static void batchCompressImg(BatchCompressImgVO batchCompressImgVO,HttpServletResponse res)
	{
		int saveCode = 0;
		// 图片处理方式 1按照传递的日期来处理 2全部处理
		try 
		{
			// 图片原图父地址
			String imgUrl = getUploadPath();
			// 图片缩略图目标地址
			String saveURL = getCompressPath();
			// 日期
			String handle_date = batchCompressImgVO.getIs_all_batch();
			// 是否全部执行
			String is_all_batch = batchCompressImgVO.getHandle_date();
			//判断
			if(handle_date!=null&&!"".equals(handle_date))
			{
				saveCode=1;
			}
			else if(is_all_batch!=null&&"1".equals(is_all_batch))
			{
				// 是否全部处理
				saveCode=2;
			}
			//判断
			if(saveCode==1)
			{
				File file=new File(imgUrl+handle_date);
				// 判断
				if (file.exists())
				{
					File[] fileList = file.listFiles();
					fileList[0].getPath();
				}	
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * @Title: getFileBatchZIP
	 * @Description: TODO(文件打包压缩zip包)
	 * @param batchCompressImgVO
	 * @param res
	 * @author: baisong
	 * @time:2016年10月31日 下午1:48:12 history: 1、2016年10月31日 baisong 创建方法
	 */
	public static void getFileBatchZIP(BatchCompressImgVO batchCompressImgVO,HttpServletResponse res)
	{
		Gson gson = new Gson();
		try 
		{
			List<BatchCompressImgVO> attList = gson.fromJson(
					batchCompressImgVO.getFile_address(),
					new TypeToken<List<BatchCompressImgVO>>() 
					{
					}.getType());
			// 文件总路径
			String pareUrl = getUploadPath();
			List<File> fileList = new ArrayList<>();
			//循环
			for (BatchCompressImgVO url : attList)
			{
				// 循环获取图片文件
				File file = new File(pareUrl + url.getAttachment_address());
				//判断
				if (file.exists()) 
				{
					fileList.add(file);
				}

			}
			ZipFile.downLoadFiles(fileList, res, attList);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}

    /**
     * @Title: saveCreditProtocolPDF
     * @Description: 保存生成的债权合同pdf文件
     * @param inputStream
     * @param bill_code
     * @param originalFilename 
     * @author: Guanxu
     * @time:2017年3月17日 下午5:04:42
     * history:
     * 1、2017年3月17日 Guanxu 创建方法
    */
    public static String saveCreditProtocolPDF(InputStream fileStream, String bill_code, String srcFileName)
    {
        // 将传入的files转成byte数组
        // byte[] bytes = files.getBytes(Charset.forName("UTF_8"));
        String catalog = DateUtil.date2String(new Date(), "yyyyMM");
        String postfix = "";
		// 判断
        if (srcFileName.lastIndexOf(".") > -1)
        {
            postfix = srcFileName.substring(srcFileName.lastIndexOf(".")).toLowerCase();
        }
        // String fileName = file_name;
		// String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");
        String realPath = "";
		// 判断
        if ("1".equals(isDebug))
        {
            String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
            nowPath = nowPath.substring(0, nowPath.indexOf("WEB-INF"));
            realPath = nowPath + "/resources/upload/" + bill_code + "/" + catalog;
        }
        else
        {
			// realPath = PlatformGlobalVar.SYS_PROPERTIES.get("realUploadCatalog") + "/" +
			// bill_code + "/" + catalog;
			realPath = GlobalVal.getProperty("realUploadCatalog") + "/" + bill_code + "/" + catalog;

        }

        File dir = new File(realPath);
		// 判断
        if (!dir.exists())
        {
            dir.mkdirs();
        }
        FileOutputStream fout;
        try
        {
            String fileNameDate = new Date().getTime() + ".pdf";
            realPath += "/" + fileNameDate;
            fout = new FileOutputStream(new File(realPath));
            BufferedInputStream bis = new BufferedInputStream(fileStream);
            byte[] cacheArray = new byte[2048];
            int size;
			// 循环
            while ((size = bis.read(cacheArray)) != -1)
            {
                fout.write(cacheArray, 0, size);
            }
            fout.flush();
            fout.close();
            bis.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return realPath;
    }
    
    /**
	 * @author wangyihan
	 * @param 1、上传的文件流，2、当前用户的ID，3、上传文件名
	 * @return 返回保存的文件路径
	 * */
	public static String uploadProtocolTemplateForIFC(InputStream fileStream, String userId,
			String srcFileName) throws IOException
	{
		
		String catalog = DateUtil.date2String(new Date(), "yyyyMM");
		String postfix = "";
		//判断
		if (srcFileName.lastIndexOf(".") > -1) 
		{
		    postfix = srcFileName.substring(srcFileName.lastIndexOf(".")).toLowerCase(); 
		}
		String fileName = "" + System.currentTimeMillis();
		// String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");
		String isDebug = GlobalVal.getProperty("isDebugUpload");
		String realPath = "";
		//判断
		if ("1".equals(isDebug))
		{
			String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
			nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
			realPath = nowPath + "/resources/upload/" + catalog;
		}
		else
		{
			// realPath =
			// PlatformGlobalVar.SYS_PROPERTIES.get("realProtocolTemplateCatalog") + "/" +
			// catalog;
			realPath = GlobalVal.getProperty("isDebugUpload") + "/" + catalog;

		}

		File dir = new File(realPath);
		//判断
		if (!dir.exists()) 
		{
			dir.mkdirs();
		}
		FileOutputStream fout = new FileOutputStream(new File(realPath + "/" + fileName + postfix));
		
		BufferedInputStream bis = new BufferedInputStream(fileStream);
		byte[] cacheArray = new byte[2048];
		int size;
		//循环
		while ((size = bis.read(cacheArray)) != -1)
		{
			fout.write(cacheArray, 0, size);
		}

		fout.close();   
		bis.close();    
		return "/" + catalog + "/" + fileName + postfix;
	}
	
	/**
	 * @author wangyihan
	 * @param 1、上传的文件流，2、当前用户的ID，3、上传文件名
	 * @return 返回保存的文件路径
	 * */
	public static String uploadProtocolTemplateForIFCByRestTemplate(InputStream fileStream, String userId,
			String srcFileName) throws IOException 
	{
		
		String catalog = DateUtil.date2String(new Date(), "yyyyMM");
		String postfix = "";
		//判断
		if (srcFileName.lastIndexOf(".") > -1) 
		{
		    postfix = srcFileName.substring(srcFileName.lastIndexOf(".")).toLowerCase(); 
		}
		String fileName = "" + System.currentTimeMillis();
		String isDebug = PlatformGlobalVar.SYS_PROPERTIES.get("isDebugUpload");

		String realPath = "";
		//判断
		if ("1".equals(isDebug)) 
		{
			String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
			nowPath = nowPath.substring(0,nowPath.indexOf("WEB-INF"));
			realPath = nowPath + "/resources/upload/" + catalog;
		}
		else
		{
			realPath = GlobalVal.getProperty("realUploadCatalog") + "/" + catalog;
		}

		File dir = new File(realPath);
		//判断
		if (!dir.exists()) 
		{
			dir.mkdirs();
		}
		FileOutputStream fout = new FileOutputStream(new File(realPath + "/" + fileName + postfix));
		
		BufferedInputStream bis = new BufferedInputStream(fileStream);
		byte[] cacheArray = new byte[2048];
		int size;
		//循环
		while ((size = bis.read(cacheArray)) != -1)
		{
			fout.write(cacheArray, 0, size);
		}

		fout.close();   
		bis.close();    
		return "/" + catalog + "/" + fileName + postfix;
	}
	
	/**
     * @author wangyihan
     * @param 1、上传的文件流，2、当前用户的ID，3、上传文件名
     * @return 返回保存的文件路径
     * */
    public static String uploadProtocolTemplateForIFC(InputStream fileStream, String userId,
            String srcFileName, String catalog) throws IOException 
    {
        
		String isDebug = GlobalVal.getProperty("isDebugUpload");
        String realPath = "";
      //判断
        if ("1".equals(isDebug)) 
        {
            String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
            nowPath = nowPath.substring(0, nowPath.indexOf("WEB-INF"));
            realPath = nowPath + "/resources/upload/" + catalog;
        }
        else 
        {
			realPath = GlobalVal.getProperty("realProtocolTemplateCatalog") + "/" + catalog;
        }

        File dir = new File(realPath);
      //判断
        if (!dir.exists())
        {
            dir.mkdirs();
        }
        FileOutputStream fout = new FileOutputStream(new File(realPath + "/" + srcFileName));
        
        BufferedInputStream bis = new BufferedInputStream(fileStream);
        byte[] cacheArray = new byte[2048];
        int size;
        //循环
        while ((size = bis.read(cacheArray)) != -1) 
        {
            fout.write(cacheArray, 0, size);
        }
        fout.close();   
        bis.close();    
        return realPath;
    }

    /**
     * 
     * @Title: getPathTemplateCatalog
     * @Description: TODO(获取文件拼装好的完整路径)
     * @param catalog
     * @return 
     * @author: Baisong
     * @time:2019年5月18日 上午10:24:12
     * history:
     * 1、2019年5月18日 Baisong 创建方法
     */
    public static String getPathTemplateCatalog(String catalog)
    {
		String isDebug = GlobalVal.getProperty("isDebugUpload");
        String realPath = "";
		// 判断
        if ("1".equals(isDebug))
        {
            String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
            nowPath = nowPath.substring(0, nowPath.indexOf("WEB-INF"));
            realPath = nowPath + "/resources/upload/" + catalog;
        }
        else
        {
			realPath = GlobalVal.getProperty("realProtocolTemplateCatalog") + "/" + catalog;
        }
        return realPath;
    }

    /**
     * 
     * @Title: getPathCatalog
     * @Description: TODO(获取文件拼装好的完整路径)
     * @param catalog
     * @return 
     * @author: Baisong
     * @time:2019年5月18日 上午10:24:12
     * history:
     * 1、2019年5月18日 Baisong 创建方法
     */
    public static String getPathCatalog(String catalog)
    {
		String isDebug = GlobalVal.getProperty("isDebugUpload");
        String realPath = "";
		// 判断
        if ("1".equals(isDebug))
        {
            String nowPath = GlobalFileUtil.class.getClassLoader().getResource("/").getPath();
            nowPath = nowPath.substring(0, nowPath.indexOf("WEB-INF"));
            realPath = nowPath + "/resources/upload/" + catalog;
        }
        else
        {
			realPath = GlobalVal.getProperty("realUploadCatalog") + "/" + catalog;
        }
        return realPath;
    }
}
